USE msdb
GO

CREATE TABLE #FolderList ( folderid uniqueidentifier, parentfolderid uniqueidentifier, foldername varchar(128) )
GO

INSERT #FolderList 
     ( folderid, parentfolderid, foldername )
EXEC msdb.dbo.sp_ssis_listfolders '00000000-0000-0000-0000-000000000000'
GO

IF NOT EXISTS ( SELECT 'X' FROM #FolderList WHERE foldername = 'NCLSQLInventory' )
BEGIN
     EXEC msdb.dbo.sp_ssis_addfolder '00000000-0000-0000-0000-000000000000',N'NCLSQLInventory'
END
GO

TRUNCATE TABLE #FolderList
GO

INSERT #FolderList 
     ( folderid, parentfolderid, foldername )
EXEC msdb.dbo.sp_ssis_listfolders '00000000-0000-0000-0000-000000000000'
GO

DECLARE @folderid uniqueidentifier

SELECT @folderid = folderid 
FROM   #FolderList 
WHERE  foldername = 'NCLSQLInventory'

IF NOT EXISTS ( SELECT 'X' FROM #FolderList WHERE foldername = 'Master' )
BEGIN
     EXEC msdb.dbo.sp_ssis_addfolder @folderid,N'Master'
END

IF NOT EXISTS ( SELECT 'X' FROM #FolderList WHERE foldername = 'Collection' )
BEGIN
     EXEC msdb.dbo.sp_ssis_addfolder @folderid,N'Collection'
END
GO

DROP TABLE #FolderList
GO
